package com.pingancar.creditmanage.dao;

import com.pingancar.creditmanage.pojo.CashPojo;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by SilverStone-WW on 2015/2/15.
 */
@Repository
public class CashDaoImpl extends BaseDAO<CashPojo> {

    public List cashlist (Integer offset, Integer len, boolean cashed) {
        String hql = "from CashPojo cp where cp.confirmtime ";
        if (cashed)
            hql += "is not null";
        else
            hql += "is null";

        Query query = getSession().createQuery(hql);
        query.setFirstResult(offset).setMaxResults(len);
        return query.list();
    }

    public Long countOfCashlist (boolean cashed) {
        String hql = "select count(cp.id) from CashPojo cp where cp.confirmtime ";
        if (cashed)
            hql += "is not null";
        else
            hql += "is null";

        return (Long)getSession().createQuery(hql).uniqueResult();
    }
}
